package com.douqu.game.core.config;

import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.e.E_ShareType;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

/**
 * @author: miracle.
 * Description:
 * Date: 2018/5/24 0024 上午 11:16
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class ShareConfig extends GameObject{

    public String showIntro, showIcon, shareIcon, shareUrl, shareTitle, shareContent;
    /** 类型 */
    public int type;

    /** 条件 */
    public String condition;

    public int afterShare;

    /** 等级 */
    public int level;

    /** 奖励 */
    public GoodsData reward;

    @Override
    public boolean check() {
        if (type <= 0){
            LogUtils.error("ShareConfig check type is error -> id:" + id + " name:" + name);
            return false;
        }
        if (reward == null){
            LogUtils.error("ShareConfig check reward is null -> id:" + id + " name:" + name);
            return false;
        }
        if (type == E_ShareType.MAJORLEVELUP.getCode() || type == E_ShareType.ORANGENUMBER.getCode()
                || type == E_ShareType.REDNUMBER.getCode() || type == E_ShareType.PURPLEUPSTAR.getCode()
                || type == E_ShareType.ORANGEUPSTAR.getCode() || type == E_ShareType.REDUPSTAR.getCode()
                || type == E_ShareType.PASSCUSTOMS.getCode() || type == E_ShareType.SENIORITYRANK.getCode()){
            try {
                level = Integer.valueOf(condition);
            }catch (Exception e){
                LogUtils.error("ShareConfig check level is error -> id:" + id + " name:" + name);
                return false;
            }
        }
        return true;
    }

    @Override
    public boolean setVariable(String key, String value) {
        if ("reward".equals(key)){
            GoodsData[] temp = LoadUtils.loadGoodDataToArray(key, value);
            if(temp.length == 0){
                reward = new GoodsData(0, Integer.MAX_VALUE, 0);
            }else {
                reward = temp[0];
            }
            return true;
        }else{
            return super.setVariable(key, value);
        }
    }
}
